<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>服务器健康状态报告</title>
    <style>
        /* 全局样式 */
        :root {
            --primary-color: #3498db;
            --success-color: #2ecc71;
            --warning-color: #f39c12;
            --danger-color: #e74c3c;
            --gray-light: #f5f5f5;
            --gray-medium: #e0e0e0;
            --gray-dark: #666;
            --border-radius: 6px;
            --box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            --transition: all 0.3s ease;
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        body {
            font-family: "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f9f9f9;
            color: #333;
            line-height: 1.6;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        /* 页眉 */
        .header {
            background: linear-gradient(135deg, var(--primary-color), #2980b9);
            color: white;
            padding: 30px 20px;
            text-align: center;
            border-radius: var(--border-radius);
            margin-bottom: 20px;
            box-shadow: var(--box-shadow);
        }
        
        .header h1 {
            margin: 0;
            font-size: 28px;
            font-weight: 500;
            letter-spacing: 1px;
        }
        
        .report-time {
            margin-top: 10px;
            font-size: 14px;
            opacity: 0.9;
        }
        
        /* 卡片容器 */
        .card {
            background-color: white;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            margin-bottom: 20px;
            overflow: hidden;
        }
        
        .card-header {
            background-color: #f8f9fa;
            padding: 15px 20px;
            border-bottom: 1px solid var(--gray-medium);
        }
        
        .card-header h2 {
            margin: 0;
            font-size: 18px;
            font-weight: 500;
            color: #444;
        }
        
        .card-body {
            padding: 0;
        }
        
        /* 表格 */
        table {
            width: 100%;
            border-collapse: collapse;
            border: none;
            margin-bottom: 0;
        }
        
        th, td {
            padding: 12px 15px;
            text-align: left;
            border: none;
            border-bottom: 1px solid var(--gray-medium);
            font-size: 14px;
        }
        
        th {
            background-color: #f8f9fa;
            font-weight: 500;
            color: var(--gray-dark);
            position: sticky;
            top: 0;
        }
        
        tr:last-child td {
            border-bottom: none;
        }
        
        tr:nth-child(even):not(.details-row) {
            background-color: #f8f9fa;
        }
        
        .server-row {
            cursor: pointer;
            transition: var(--transition);
        }
        
        .server-row:hover {
            background-color: rgba(52, 152, 219, 0.05) !important;
        }
        
        .server-row.active {
            background-color: rgba(52, 152, 219, 0.1) !important;
        }
        
        /* 状态标签 */
        .status-label {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 50px;
            font-size: 12px;
            font-weight: 500;
            text-align: center;
            min-width: 80px;
        }
        
        .status-online {
            color: white;
            background-color: var(--success-color);
        }
        
        .status-offline {
            color: white;
            background-color: var(--danger-color);
        }
        
        /* 指标样式 */
        .metric {
            position: relative;
            padding: 3px 8px;
            border-radius: 4px;
            font-weight: 500;
        }
        
        .warning {
            background-color: rgba(243, 156, 18, 0.15);
            color: var(--warning-color);
        }
        
        .critical {
            background-color: rgba(231, 76, 60, 0.15);
            color: var(--danger-color);
        }
        
        .service-running {
            color: var(--success-color);
        }
        
        .service-stopped {
            color: var(--danger-color);
        }
        
        /* 详情部分 */
        .details-cell {
            padding: 0 !important;
            background-color: #f8f9fa;
        }
        
        .details-container {
            padding: 20px;
            border-left: 3px solid var(--primary-color);
        }
        
        .detail-block {
            margin-bottom: 20px;
        }
        
        .detail-block:last-child {
            margin-bottom: 0;
        }
        
        .detail-title {
            font-weight: 500;
            margin-bottom: 10px;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            font-size: 15px;
        }
        
        .detail-title:before {
            content: '';
            display: inline-block;
            width: 6px;
            height: 6px;
            background-color: var(--primary-color);
            margin-right: 8px;
            border-radius: 50%;
        }
        
        .detail-info {
            display: flex;
            flex-wrap: wrap;
            margin-left: 14px;
        }
        
        .detail-item {
            margin-right: 20px;
            margin-bottom: 10px;
            font-size: 14px;
        }
        
        .detail-item strong {
            color: #555;
            font-weight: 500;
        }
        
        /* 内部表格 */
        .inner-table {
            width: 100%;
            margin-top: 10px;
            margin-left: 14px;
            background-color: white;
            border-radius: var(--border-radius);
            box-shadow: 0 1px 3px rgba(0,0,0,0.05);
            overflow: hidden;
        }
        
        .inner-table th, .inner-table td {
            padding: 10px;
            font-size: 13px;
        }
        
        /* 错误日志 */
        .error-list {
            margin-left: 30px;
            margin-top: 10px;
        }
        
        .error-list li {
            font-size: 13px;
            color: #555;
            margin-bottom: 5px;
        }
        
        /* 切换图标 */
        .toggle-icon {
            display: inline-flex;
            justify-content: center;
            align-items: center;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            background-color: var(--primary-color);
            color: white;
            font-size: 14px;
            margin-right: 5px;
            transition: var(--transition);
        }
        
        .toggle-icon.open {
            transform: rotate(180deg);
            background-color: #2980b9;
        }
        
        /* 响应式调整 */
        @media (max-width: 768px) {
            .container {
                padding: 10px;
            }
            
            th, td {
                padding: 10px;
            }
            
            .header {
                padding: 20px;
            }
            
            .header h1 {
                font-size: 22px;
            }
            
            .hidden-mobile {
                display: none;
            }
        }
        
        /* 加载动画 */
        @keyframes pulse {
            0% { box-shadow: 0 0 0 0 rgba(52, 152, 219, 0.4); }
            70% { box-shadow: 0 0 0 10px rgba(52, 152, 219, 0); }
            100% { box-shadow: 0 0 0 0 rgba(52, 152, 219, 0); }
        }
        
        .loading .toggle-icon {
            animation: pulse 1.5s infinite;
        }
        
        /* 进度条 */
        .progress-bar {
            height: 8px;
            width: 100%;
            background-color: #f0f0f0;
            border-radius: 4px;
            overflow: hidden;
            margin-top: 5px;
        }
        
        .progress-fill {
            height: 100%;
            background-color: var(--primary-color);
            transition: width 0.2s ease;
        }
        
        .progress-fill.warning {
            background-color: var(--warning-color);
        }
        
        .progress-fill.critical {
            background-color: var(--danger-color);
        }
        
        /* 隐藏行 */
        .hidden {
            display: none;
        }
    </style>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 切换服务器详情显示
            function toggleDetails(id) {
                const detailsRow = document.getElementById('details-' + id);
                const toggleIcon = document.getElementById('toggle-' + id);
                const serverRow = document.getElementById('server-' + id);
                
                if (detailsRow.classList.contains('hidden')) {
                    // 显示详情
                    detailsRow.classList.remove('hidden');
                    toggleIcon.innerHTML = '&ndash;';
                    toggleIcon.classList.add('open');
                    serverRow.classList.add('active');
                } else {
                    // 隐藏详情
                    detailsRow.classList.add('hidden');
                    toggleIcon.innerHTML = '+';
                    toggleIcon.classList.remove('open');
                    serverRow.classList.remove('active');
                }
            }
            
            // 为所有服务器行添加点击事件
            const serverRows = document.querySelectorAll('.server-row');
            serverRows.forEach(row => {
                const id = row.getAttribute('data-server-id');
                row.addEventListener('click', function() {
                    toggleDetails(id);
                });
            });
            
            // 默认展开所有离线服务器的详情
            const offlineServers = document.querySelectorAll('.status-offline');
            offlineServers.forEach(statusCell => {
                const row = statusCell.closest('tr');
                const id = row.getAttribute('data-server-id');
                toggleDetails(id);
            });
            
            // 为所有进度条设置宽度
            const progressBars = document.querySelectorAll('.progress-bar');
            progressBars.forEach(bar => {
                const percentText = bar.getAttribute('data-percent');
                const percent = parseFloat(percentText.replace('%', ''));
                const fill = bar.querySelector('.progress-fill');
                
                fill.style.width = percent + '%';
                
                if (percent > 90) {
                    fill.classList.add('critical');
                } else if (percent > 70) {
                    fill.classList.add('warning');
                }
            });
        });
    </script>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>服务器健康状态报告</h1>
            <div class="report-time">生成时间: ${reportTime}</div>
        </div>
        
        <div class="card">
            <div class="card-header">
                <h2>服务器状态概览</h2>
            </div>
            <div class="card-body">
                <table>
                    <thead>
                        <tr>
                            <th style="width: 30px;"></th>
                            <th>ID</th>
                            <th>名称</th>
                            <th>主机地址</th>
                            <th style="width: 100px;">状态</th>
                            <th>CPU使用率</th>
                            <th>内存使用情况</th>
                            <th class="hidden-mobile">系统负载</th>
                        </tr>
                    </thead>
                    <tbody>
                        <#list servers as server>
                        <tr id="server-${server.server.id}" class="server-row" data-server-id="${server.server.id}">
                            <td>
                                <div id="toggle-${server.server.id}" class="toggle-icon">+</div>
                            </td>
                            <td>${server.server.id}</td>
                            <td>${server.server.name}</td>
                            <td>${server.server.host}</td>
                            <#if server.online>
                            <td><span class="status-label status-online">在线</span></td>
                            <td>
                                <#if server.cpuUsage??>
                                <#assign cpuValue = server.cpuUsage?replace("%", "")?number>
                                <#assign cpuClass = "">
                                <#if cpuValue gt 90>
                                    <#assign cpuClass = "critical">
                                <#elseif cpuValue gt 70>
                                    <#assign cpuClass = "warning">
                                </#if>
                                <div>
                                    <span class="metric ${cpuClass}">${server.cpuUsage}</span>
                                    <div class="progress-bar" data-percent="${cpuValue}">
                                        <div class="progress-fill"></div>
                                    </div>
                                </div>
                                <#else>
                                <span>N/A</span>
                                </#if>
                            </td>
                            <td>
                                <#if server.memoryInfo??>
                                <#assign memParts = server.memoryInfo?split(" / ")>
                                <#if memParts?size gte 2 && memParts[1]?contains("(")>
                                    <#assign totalWithPercent = memParts[1]>
                                    <#assign memPercent = totalWithPercent?substring(totalWithPercent?index_of("(") + 1, totalWithPercent?index_of("%"))>
                                    <#assign memClass = "">
                                    <#if memPercent?number gt 90>
                                        <#assign memClass = "critical">
                                    <#elseif memPercent?number gt 70>
                                        <#assign memClass = "warning">
                                    </#if>
                                    <div>
                                        <span>${memParts[0]} / ${totalWithPercent?substring(0, totalWithPercent?index_of("("))}</span>
                                        <span class="metric ${memClass}">(${memPercent}%)</span>
                                        <div class="progress-bar" data-percent="${memPercent}">
                                            <div class="progress-fill"></div>
                                        </div>
                                    </div>
                                <#else>
                                    ${server.memoryInfo}
                                </#if>
                                <#else>
                                <span>N/A</span>
                                </#if>
                            </td>
                            <td class="hidden-mobile">${server.systemLoad!('N/A')}</td>
                            <#else>
                            <td><span class="status-label status-offline">离线</span></td>
                            <td colspan="3">${server.errorMessage!('连接失败')}</td>
                            </#if>
                        </tr>
                        <tr id="details-${server.server.id}" class="details-row hidden">
                            <td colspan="8" class="details-cell">
                                <div class="details-container">
                                    <#if !server.online>
                                    <div class="detail-block">
                                        <div class="detail-title">错误信息</div>
                                        <div class="detail-info">
                                            <span style="color: var(--danger-color);">${server.errorMessage!('连接失败')}</span>
                                        </div>
                                    </div>
                                    <#else>
                                    <div class="detail-block">
                                        <div class="detail-title">基本信息</div>
                                        <div class="detail-info">
                                            <#if server.uptime??>
                                            <div class="detail-item"><strong>运行时间:</strong> ${server.uptime}</div>
                                            </#if>
                                            <#if server.processCount??>
                                            <div class="detail-item"><strong>进程数:</strong> ${server.processCount}</div>
                                            </#if>
                                            <#if server.networkConnections??>
                                            <div class="detail-item"><strong>网络连接数:</strong> ${server.networkConnections}</div>
                                            </#if>
                                            <#if server.systemLoad??>
                                            <div class="detail-item"><strong>系统负载:</strong> ${server.systemLoad}</div>
                                            </#if>
                                        </div>
                                    </div>
                                    
                                    <#if server.diskInfoList?? && server.diskInfoList?size gt 0>
                                    <div class="detail-block">
                                        <div class="detail-title">磁盘空间</div>
                                        <table class="inner-table">
                                            <thead>
                                                <tr>
                                                    <th>挂载点</th>
                                                    <th>已用</th>
                                                    <th>总计</th>
                                                    <th style="width: 30%;">使用率</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <#list server.diskInfoList as disk>
                                                <tr>
                                                    <td>${disk.mountPoint}</td>
                                                    <td>${disk.used}</td>
                                                    <td>${disk.total}</td>
                                                    <#assign diskPercent = disk.percentage?replace("%", "")?number>
                                                    <#assign diskClass = "">
                                                    <#if diskPercent gt 90>
                                                        <#assign diskClass = "critical">
                                                    <#elseif diskPercent gt 75>
                                                        <#assign diskClass = "warning">
                                                    </#if>
                                                    <td>
                                                        <span class="metric ${diskClass}">${disk.percentage}</span>
                                                        <div class="progress-bar" data-percent="${diskPercent}">
                                                            <div class="progress-fill"></div>
                                                        </div>
                                                    </td>
                                                </tr>
                                                </#list>
                                            </tbody>
                                        </table>
                                    </div>
                                    </#if>
                                    
                                    <#if server.serviceStatus?? && server.serviceStatus?size gt 0>
                                    <div class="detail-block">
                                        <div class="detail-title">关键服务状态</div>
                                        <table class="inner-table">
                                            <thead>
                                                <tr>
                                                    <th>服务名称</th>
                                                    <th>状态</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <#list server.serviceStatus?keys as service>
                                                <tr>
                                                    <td>${service}</td>
                                                    <#assign serviceClass = "">
                                                    <#if server.serviceStatus[service] == "运行中">
                                                        <#assign serviceClass = "service-running">
                                                    <#elseif server.serviceStatus[service] == "已停止" || server.serviceStatus[service] == "未安装">
                                                        <#assign serviceClass = "service-stopped">
                                                    </#if>
                                                    <td>
                                                        <span class="${serviceClass}">${server.serviceStatus[service]}</span>
                                                    </td>
                                                </tr>
                                                </#list>
                                            </tbody>
                                        </table>
                                    </div>
                                    </#if>
                                    
                                    <#if server.recentErrors?? && server.recentErrors?size gt 0>
                                    <div class="detail-block">
                                        <div class="detail-title">最近系统错误</div>
                                        <ul class="error-list">
                                            <#list server.recentErrors as error>
                                            <li>${error}</li>
                                            </#list>
                                        </ul>
                                    </div>
                                    </#if>
                                    </#if>
                                </div>
                            </td>
                        </tr>
                        </#list>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html> 